<template>
	<view class="workCenter">
		<view class="tabsHeaders" style="width: 100%;">
			<u-tabs :list="tabList" is-scroll="false" gutter="75" bar-height="6" bar-width="60" :current="current" @change="changeTab"></u-tabs>
			<u-search placeholder="请输入款号" shape="square" @clear='clearSearch' @custom='searchList'  margin="25rpx 35rpx" class="searchBox" v-model="searchData.goodsItemNo"></u-search>
			<goods-item :sendList="dataList" :tabState="current"></goods-item>
		</view>
		<uni-nodata v-if="zeroLength"></uni-nodata>
		<!-- <u-empty text=" " v-if="zeroLength" mode="list"></u-empty> -->
		<u-divider v-if="showBotom">到底了</u-divider>
	</view>
</template>

<script>
import goodsItem from './goodsItem.vue';
export default {
	components: {
		goodsItem
	},
	data() {
		return {
			zeroLength: false,
			showBotom: true,
			searchData: {
				pageIndex: 0,
				pageSize: 10,
				goodsItemNo:'',
				workOrderQueryAndroidStatusEnum: 'STATUS_ACCEPT_ORDER'
			},
			dataList: [],
			tabList: [{ name: '待处理' }, { name: '进行中' }, { name: '历史工单' }],
			current: 0
		};
	},
	onShow() {
		console.log(this.$imgUrl);
		this.dataList = [];
		this.searchData.pageIndex = 0;
		this.getDataList();
	},
	onReachBottom() {
		console.log('1234567890');
		if (this.showBotom) {
			return;
		} else {
			this.searchData.pageIndex = Number(this.searchData.pageIndex + 1);
			this.getDataList('push');
		}
	},
	onPullDownRefresh() {
		console.log('refresh');
		this.dataList = [];
		this.searchData.pageIndex = 0;
		this.searchData.pageSize = 10;
		this.getDataList();
	},
	methods: {
		resectList(){
			this.dataList = [];
			this.searchData.pageIndex = 0;
			this.searchData.pageSize = 10;
			this.getDataList();
		},
		clearSearch(){
			console.log('///')
			this.resectList()
		},
		searchList(val){
			console.log(val)
			this.searchData.goodsItemNo = val
			this.resectList()
		},
		getDay(dateTime) {
			var EndTime = new Date(dateTime);
			// 当前系统时间
			var NowTime = new Date();
			var t = EndTime.getTime() - NowTime.getTime();
			var d = Math.floor(t / 1000 / 60 / 60 / 24);
			var html = d + ' 天';
			console.log(html);
			return html;
		},
		getDataList(val) {
			console.log(val);
			this.$store.dispatch('getFactoryWorkOrderList', this.searchData).then(res => {
				if (res.data.errorCode === 0) {
					console.log(res);
					let result = res.data.data;

					if (result.content.length > 0) {
						result.content.forEach(item => {
							item.upDay = this.getDay(item.replyDeliveryDate);
						});
					}
					if (this.searchData.pageIndex >= res.data.data.totalPages) {
						this.showBotom = true;
						this.zeroLength = false;
					} else {
						this.zeroLength = false;
						this.showBotom = false;
						this.dataList = this.dataList.concat(res.data.data.content);
					}
					if (this.dataList.length == 0) {
						this.zeroLength = true;
						this.showBotom = false;
					}
				}
			});
		},
		getImgUrl(img) {
			return 'http://files.ybangy.net/' + img;
		},
		changeTab(index) {
			this.searchData.goodsItemNo = ''
			console.log(index);
			this.current = index;
			this.searchData.pageIndex = 0;
			this.dataList = [];
			switch (index) {
				case 0:
					this.searchData.workOrderQueryAndroidStatusEnum = 'STATUS_ACCEPT_ORDER';
					this.getDataList();
					break;
				case 1:
					this.searchData.workOrderQueryAndroidStatusEnum = 'STATUS_MACHINING';
					this.getDataList();
					break;
				case 2:
					this.searchData.workOrderQueryAndroidStatusEnum = 'STATUS_COMPLETED';
					this.getDataList();
					break;
			}
		}
	}
};
</script>

<style scoped lang="scss">
.workCenter {
	background-color: $uni-bg-color;
	min-height: 100vh;
	.searchBox{
		// padding: 15rpx 35rpx;
	}
}

</style>
